/**
 * 
 */
package com.dp.behav.visitor;

import java.util.ArrayList;

/**
 * This is an example of visitor design pattern. It allows one or more operation
 * to be applied to a set of objects at runtime, decoupling the operations from
 * the object structure.Represents an operation to be performed on the elements
 * of an object structure. Visitor lets you define a new operation without
 * changing the classes of the elements on which it operates.
 * 
 * @author Sunaina.Sharma
 * 
 */
public class VisitorEx {

	public class ShoppingCart {
		// normal shopping cart stuff
		private ArrayList<Visitable> items;

		/**
		 * @return
		 */
		public double calculatePostage() {
			// create a visitor
			PostageVisitor visitor = new PostageVisitor();
			// iterate through all items
			for (Visitable item : items) {
				item.accept(visitor);
			}
			double postage = visitor.getTotalPostage();
			return postage;

		}

	}
}
